from tortoise import fields
from tortoise.models import Model

class Agent(Model):
    """智能体模型，存储AI智能体的配置和状态"""
    id = fields.IntField(pk=True, description="自增主键")
    name = fields.CharField(max_length=64, description="智能体名称")
    description = fields.TextField(null=True, description="智能体描述")
    avatar = fields.TextField(null=True, description="头像")
    category = fields.CharField(max_length=64, null=True, description="智能体分类")
    agent_type = fields.CharField(max_length=32, description="智能体类型包括类型（内嵌、外链）")
    status = fields.CharField(max_length=32, description="智能体状态，如：active, inactive, deleted等")
    config = fields.JSONField(null=True, description="智能体配置: 接口url，模型id，apikey，max_token等")
    created_by = fields.ForeignKeyField("models.User", related_name="created_agents", null=True, description="创建者")
    department = fields.ForeignKeyField("models.Department", related_name="department_agents", null=True, description="所属部门")
    version = fields.CharField(max_length=16, default="1.0.0", description="版本号")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")
    
    class Meta:
        table = "agent"
        table_description = "智能体表"
        ordering = ["-created_at"]
